const initialState = {
  userInfo: {} as IUserInfo,
  profile: {} as IProfile,
};

type ActionType =
  | { type: 'user/saveUserInfo'; payload: IUserInfo }
  | { type: 'user/saveProfile'; payload: IProfile };

export default function userReducer(
  state = initialState,
  action: ActionType
): typeof initialState {
  switch (action.type) {
    case 'user/saveUserInfo':
      return {
        ...state,
        userInfo: action.payload,
      };
    case 'user/saveProfile':
      return {
        ...state,
        profile: action.payload,
      };
    default:
      return state;
  }
}

interface IUserInfo {
  id: string;
  name: string;
  photo: string;
  art_count: number;
  follow_count: number;
  fans_count: number;
  like_count: number;
}

export interface IProfile {
  id: string;
  photo: string;
  name: string;
  mobile: string;
  gender: number;
  birthday: string;
  intro: string;
}
